//多数元素 摩尔投票法  时间复杂度O(n) 空间复杂度O(1)  力扣169
class Solution1 {
    public int majorityElement(int[] nums) {
        int count = 0;
        Integer candidate = null;

        for (int num : nums) {
            if (count == 0) {
                candidate = num;
            }
            count += (num == candidate) ? 1 : -1;
        }

        return candidate;
    }
}
